package cn.edu.lingnan.service;

import cn.edu.lingnan.dao.IStudentDao;
import cn.edu.lingnan.dao.StudentDao;
import cn.edu.lingnan.pojo.Student;

import java.util.List;

public class IStudentService implements StudentService{

    StudentDao studentDao = new IStudentDao();

    @Override
    public Student studentLogin(int id, String password) {
        return studentDao.studentLogin(id,password);
    }

    @Override
    public Student findStudentById(int id) {
        return studentDao.findStudentById(id);
    }

    @Override
    public List<Student> findStudentAll() {
        return studentDao.findStudentAll();
    }

    @Override
    public List<Student> getStudentByName(String _name) {
        return studentDao.getStudentByName(_name);
    }

    @Override
    public boolean addStudent(Student student) {
        int result = studentDao.addStudent(student);
        if(result==1){
            return true;//添加成功
        } else{
            return false;//添加失败
        }
    }

    @Override
    public boolean delStudent(int id) {
        int result = studentDao.delStudent(id);
        if(result==1){
            return true;//删除成功
        }else {
            return false;//删除失败
        }
    }

    @Override
    public boolean updateStudent(Student student) {
        int result = studentDao.updateStudent(student);
        if(result==1){
            return true;//修改成功
        }else {
            return false;//修改失败
        }
    }

    @Override
    public boolean updateStuFlag(int sid) {
        int flag = studentDao.updateStuFlag(sid);
        if(flag==1){
            return true;
        }else {
            return false;
        }
    }
    public boolean changePassword(int id, String oldPassword, String newPassword) {
        // 验证旧密码
        if (studentDao.checkPassword(id, oldPassword)) {
            // 更新密码
            return studentDao.updatePassword(id, newPassword);
        }
        return false;
    }

    @Override
    public boolean resetPassword(String userId) {
        return studentDao.resetPassword(userId);
    }
}
